package com.macrounion.atv.controller.api;

import com.macrounion.atv.service.dto.ProtocolONIDto;
import com.macrounion.atv.service.entity.Net;
import com.macrounion.atv.service.entity.ProtocolC;
import com.macrounion.atv.service.entity.ext.ProtocolExt;
import com.macrounion.base.annotation.Auth;
import com.macrounion.base.service.dto.PageRespDto;
import com.macrounion.base.service.dto.StringRespDto;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import com.macrounion.atv.processor.ProtocolProcessor;
import com.macrounion.atv.service.entity.Protocol;
import com.macrounion.atv.service.entity.User;
import com.macrounion.atv.service.service.ProtocolService;
import com.macrounion.base.controller.api.BaseApiController;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/protocol")
public class ProtocolApiController extends BaseApiController<Protocol, ProtocolExt, ProtocolProcessor, ProtocolService, Protocol, User> {

    @GetMapping("/protocolmap")
    public Map<String, List<ProtocolC>> getProtocolMap(List<String> pids) {
        return processor.getProtocolMap(pids);
    }

    @GetMapping("/nets")
    public List<Net> getNets() {
        return processor.getNets();
    }

    @ApiOperation("扩展分页查询")
    @PostMapping({"/requestPageExt"})
    @Auth(
            requireAuth = true,
            actionCode = {"view"}
    )
    public PageRespDto<ProtocolExt> requestPageExt(@RequestBody Protocol req) {
        return processor.requestPageExt(req);
    }

    @GetMapping("/getProtocolListByType")
    public List<Protocol> getProtocolListByType(String type) {
        return processor.getProtocolListByType(type);
    }

    @GetMapping("/getProtocolOut")
    public ProtocolONIDto getProtocolOut(String protocolId) {
        return processor.getProtocolOut(protocolId);
    }

    @GetMapping("/getProtocolOutXml")
    public StringRespDto getProtocolOutXml(String protocolId) {
        return processor.getProtocolOutXml(protocolId);
    }

    @DeleteMapping("/deleteProtocol/{protocolId}")
    public StringRespDto deleteByProtocolId(@PathVariable String protocolId) {
        return processor.removeProtocol(protocolId);
    }

    @GetMapping("/getProtocolOutCsv")
    public StringRespDto getProtocolOutCsv(String protocolId) {
        return processor.getProtocolOutCsv(protocolId);
    }

    @PostMapping("/uploadProtocols")
    public StringRespDto importProtocols(@RequestBody StringRespDto xml) {
        return processor.importProtocols(xml.getContent());
    }

    @RequestMapping("/uploadCsv")
    public StringRespDto importProtoclsCsv(@RequestParam(value = "file", required = false) MultipartFile file){
        return processor.importProtocolsCsv(file);
    }

}